package com.jhx.mall.app.servlet;

import com.jhx.mall.app.service.DtsAdService;
import com.jhx.mall.app.service.impl.DtsAdServiceImpl;
import com.jhx.mall.entity.DtsAd;
import com.jhx.mall.util.BaseServlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "DtsAdServlet", value = "/api/index/ad")
public class DtsAdServlet extends BaseServlet {

    private DtsAdService service = null;

    @Override
    public void init(ServletConfig config) throws ServletException {
        service = new DtsAdServiceImpl();
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String opr = request.getParameter("opr");
        // 判断opr进行相应的操作
        if (opr.equals("list")) {   // 查询所有广告
            List<DtsAd> dtsAdList = service.selectAll();
            if (dtsAdList != null){
                ok(request,response,dtsAdList);
            } else {
                error(request,response,dtsAdList);
            }
        }
    }
}
